# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Natanael Copa <ncopa@alpinlinux.org>
# Maintainer: Natanael Copa <ncopa@alpinlinux.org>
pkgname=lua-alt-getopt
pkgver=0.8.0
pkgrel=0
pkgdesc="Lua module for processing options similar to getopt_long(3)"
url="https://github.com/cheusov/lua-alt-getopt"
arch="noarch"
license="MIT"
source="$pkgname-$pkgver.tar.gz::https://github.com/cheusov/lua-alt-getopt/archive/$pkgver.tar.gz
	"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-alt-getopt:split_${_v/./_}"
done

package() {
	for _i in $_luaversions; do
		mkdir -p "$pkgdir"/usr/share/lua/$_i
		install -Dm644 alt_getopt.lua \
			"$pkgdir"/usr/share/lua/$_i/alt_getopt.lua
	done
}

_split() {
	local d= _ver=$1
	pkgdesc="$pkgdesc for Lua $_ver"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends=
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/
		fi
	done
}


for _v in $_luaversions; do
	eval "split_${_v/./_}() { _split $_v; }"
done

sha512sums="1c0768e98793ee060a8a70bc47355abf5feac3b51d9844a26816267c0901df9f30c9ef3280766dec2c5b754123ca548c8f49cb294bf4f04c378c62ea377e09de  lua-alt-getopt-0.8.0.tar.gz"
